﻿namespace AbpVnext_Module.Middleware
{
    public class AuthenzetionMiddleware
    {
        private RequestDelegate next;

        public AuthenzetionMiddleware(RequestDelegate requestDelegate)
        {
            this.next = requestDelegate;
        }

        public async Task InvokeAsync(HttpContext context)
        {
            //// 1、获取请求路径 /js  /html /css /
            //var path = context.Request.Path.Value;
            //if (path.Equals("/html"))
            //{
            //    await ResposeHtml(context);
            //}
            //else
            //{
            //    // 2、给下一个中间件
            //    await next(context);
            //}

            bool? bl = context.User.Identity?.IsAuthenticated;
            var path = context.Request.Path.Value;
            //throw new Exception("xxx");
            // 2、给下一个中间件
            await next(context);
            //throw new Exception("xxx");
        }

        public static async Task ResposeHtml(HttpContext httpContext)
        {
            //// 1、设置内容类型
            //httpContext.Response.ContentType = "text/html";
            //// 2、获取html文件路径
            //var filepath = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "index.html");
            //// 3、读取文件内容
            //var htmlContent = await File.ReadAllTextAsync(filepath);
            //// 4、响应输出
            //await httpContext.Response.WriteAsync(htmlContent);
        }
    }
}
